package com.system.security;

import com.system.security.domain.SelfUserEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Classname SecurityUtil
 * @Description TODO
 * @Date 2023/9/17 3:06
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class SecurityUtil {

    public static SelfUserEntity getSelfUserEntity(){
        Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
        if(authentication==null){
            return null;
        }
        if(authentication.getPrincipal()==null){
            return null;
        }
        if(authentication.getPrincipal() instanceof SelfUserEntity){
            return  (SelfUserEntity) authentication.getPrincipal();
        }
        System.out.println(authentication.getPrincipal());
        return null;

    }
}
